package com.example.newnoke.ui;

import android.content.DialogInterface;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.newnoke.R;
import com.example.newnoke.data.HongLiData;
import com.example.newnoke.data.ZhuanRuData;
import com.example.newnoke.databinding.ActivityEarningsBinding;
import com.example.newnoke.mvp.presenter.ZhuanPresenter;
import com.example.newnoke.mvp.view.IZhuanV;
import com.example.newnoke.utils.API;
import com.example.newnoke.utils.MyDialogTool;
import com.geya.jbase.baseactivity.BaseRVActivity;
import com.geya.jbase.constant.RequestType;
import com.geya.jbase.uiview.ToastUtil;

import java.util.HashMap;
import java.util.List;

public class EamingsActivity extends BaseRVActivity<HongLiData.DataBean, ZhuanPresenter> implements IZhuanV {

    private ActivityEarningsBinding mBinding;

    @Override
    public ZhuanPresenter newP() {
        return new ZhuanPresenter(this);
    }

    @Override
    public Class setClass() {
        return HongLiData.DataBean.class;
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mImmersionBar.statusBarColor(R.color.wu);
        mImmersionBar.init();
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_earnings);
        mBinding.pay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                MyDialogTool.TiShi(EamingsActivity.this, "转入提示", "是否全部转入余额？", "转入", "取消",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {

                            }
                        }, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                HashMap<String,String> map = new HashMap<>();
                                map.put("type",getIntent().getStringExtra("type"));
                                mPresennter.accessServers(RequestType.OKGO_POST, API.zhuan, ZhuanRuData.class, map);
                            }
                        }).show();

//                HashMap<String,Object> map = new HashMap<>();
//                map.put("type",getIntent().getStringExtra("type"));
//                requestData(RequestType.OKGO_GET,RequestType.ADDRESS, API.zhuan, ZhuanRuData.class,map);
            }
        });
        initBaseView();
        initRV(0,0);
        mBinding.img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mBinding.price.setText(getIntent().getStringExtra("price"));
        mBinding.name.setText(getIntent().getStringExtra("name"));
        HashMap<String,Object> map = new HashMap<>();
        map.put("type",getIntent().getStringExtra("type"));
        requestData(RequestType.OKGO_POST,RequestType.ADDRESS, API.BONUS, HongLiData.class,map);
    }

    @Override
    public BaseQuickAdapter initAdapter(List<HongLiData.DataBean> list) {
        return new BaseQuickAdapter<HongLiData.DataBean,BaseViewHolder>(R.layout.list_item_text,list) {

            @Override
            protected void convert(BaseViewHolder helper, HongLiData.DataBean item) {
                helper.setText(R.id.sj,item.getInputtime())
                        .setText(R.id.shouyi,item.getAmount())
                        .setText(R.id.bz,item.getRemark());

            }
        };
    }

    @Override
    public void pay(String s,boolean bl) {

        if (bl){
            ToastUtil.showShort("转入成功");
            mBinding.price.setText(s);
            HashMap<String, Object> map = new HashMap<>();
            map.put("type", getIntent().getStringExtra("type"));
            requestData(RequestType.OKGO_POST, RequestType.ADDRESS, API.BONUS, HongLiData.class, map);
        }else {
            ToastUtil.showShort(s);
        }



    }



    @Override
    public void showServerError(int errorCode, String errorDesc) {
     if (errorCode == -1){
         ToastUtil.showShort(errorDesc);

     }
        super.showServerError(errorCode, errorDesc);

    }
}
